using HKB.Common;
using System;
using System.IO;
using System.Web.UI;
using System.Xml;
public class HKB_ControlCache : UserControl
{
	private string m_ControlID;
	private string m_autoUpdate;
	private int m_updateCacheTime;
	public string ControlID
	{
		get
		{
			return this.m_ControlID;
		}
		set
		{
			this.m_ControlID = value;
		}
	}
	public string ControlAutoUpdate
	{
		get
		{
			return this.m_autoUpdate;
		}
		set
		{
			this.m_autoUpdate = value;
		}
	}
	public int UpdateCacheTime
	{
		get
		{
			return this.m_updateCacheTime;
		}
		set
		{
			this.m_updateCacheTime = value;
		}
	}
	protected bool CheckExistCacheFile()
	{
		string truePath = Fetch.GetTruePath("\\Label\\LabelOutPut\\ControlCache\\" + this.m_ControlID + ".config");
		return File.Exists(truePath);
	}
	protected string CreateCahcheFile()
	{
		FileIO fileIO = new FileIO();
		string str = this.m_ControlID + ".config";
		string truePath = Fetch.GetTruePath("\\Label\\LabelOutPut\\ControlCache\\" + str);
		string text = DateTime.Now.ToString();
		string strFromControl = this.GetStrFromControl();
		string templateContent = string.Concat(new string[]
		{
			"<?xml version=\"1.0\" encoding=\"GB2312\" standalone=\"yes\"?><root><LastUpdate>",
			text,
			"</LastUpdate><Content><![CDATA[",
			strFromControl,
			"]]></Content></root>"
		});
		try
		{
			fileIO.CreateTemplateFile(templateContent, truePath);
		}
		catch
		{
		}
		return strFromControl;
	}
	protected string CheckUseCacheFile()
	{
		string result;
		if (this.CheckExistCacheFile())
		{
			result = this.GetStrFromCache();
		}
		else
		{
			result = this.CreateCahcheFile();
		}
		return result;
	}
	public string GetStr()
	{
		string result;
		if (this.m_autoUpdate == "true")
		{
			result = this.CheckUseCacheFile();
		}
		else
		{
			result = this.GetStrFromControl();
		}
		return result;
	}
	public virtual string GetStrFromControl()
	{
		return "";
	}
	protected string GetStrFromCache()
	{
		XmlDocument xmlDocument = new XmlDocument();
		string str = this.m_ControlID + ".config";
		string truePath = Fetch.GetTruePath("\\Label\\LabelOutPut\\ControlCache\\" + str);
		xmlDocument.Load(truePath);
		string result;
		if (xmlDocument != null)
		{
			XmlNode xmlNode = xmlDocument.SelectSingleNode("root/LastUpdate");
			if (xmlNode != null)
			{
				DateTime value = Convert.ToDateTime(xmlNode.InnerXml);
				if (DateTime.Now.Subtract(value).TotalSeconds / 5.0 < (double)this.m_updateCacheTime)
				{
					result = xmlDocument.SelectSingleNode("root/Content").InnerXml;
					return result;
				}
				result = this.CreateCahcheFile();
				return result;
			}
		}
		result = string.Empty;
		return result;
	}
}
